<template>
  <div class="main-box">
    <div class="category-list">
      <div class="category-item">
        <Menu mode="horizontal" @on-select="select" :active-name="activeMenu" ref="activeMenu">
          <MenuItem v-for="(item,index) in categorys" :key="index" :name="item.categoryId">
            <div>
              <span style="line-height:1;">{{item.categoryName}}</span>
            </div>
          </MenuItem>
        </Menu>
      </div>
    </div>
    <div class="main">
      <div class="main-left">
        <EntryPage :categoryid="getPath" />
      </div>
      <div class="main-right">
        <MainRight />
      </div>
    </div>
  </div>
</template>

<script>
import MainRight from "../components/MainRight";
import EntryPage from "../components/EntryPage";

export default {
  name: "entrance",
  components: {
    MainRight,
    EntryPage
  },
  data() {
    return {
      categorys: [
        { categoryId: "111", categoryTitle: "frontend", categoryName: "前端" },
        { categoryId: "113", categoryTitle: "backend", categoryName: "后端" }
      ],
      activeMenu: this.$route.path.match("[^/]+(?!.*/)")[0],
      firstCategoryid: "",
      flag: false
    };
  },
  computed: {
    getPath() {
      let fulpath = this.$route.path;
      return fulpath.match("[^/]+(?!.*/)")[0];
    }
  },
  methods: {
    menuList() {
      // 这个方法里定义好，高亮和路由
      let path = this.$route.path.match("[^/]+(?!.*/)")[0];
      console.log("path: " + path);

      if (path != "entrance") {
        this.activeMenu = path;
        console.log("hello:" + this.activeMenu);
      } else {
        // this.activeMenu =
        console.log(this.categorys);

        console.log("ok:" + this.activeMenu);
      }
    },

    select(categoryId) {
      //进入路由
      this.$router.push("/entrance/" + categoryId);
      // 高亮显示路由
      this.activeMenu = this.$route.path.match("[^/]+(?!.*/)")[0];
    }
  }
};
</script>

<style lang='scss'>
.main-box {
  position: relative;
  margin: 0 auto;
  margin-top: 5rem;
  // height: 1000px;
  .category-list {
    position: fixed;
    top: 4.5rem;
    left: 0;
    right: 0;
    transition: all 0.2s;
    transform: translateZ(0);
    // transform: translate3d(0, -5rem, 0);
    z-index: 9;
    background-color: #fff;
    border-bottom: 1px solid #dcdee2;
    .category-item {
      max-width: 960px;
      width: 100%;
      margin: 0 auto;
      .item {
        position: relative;
        width: auto;
      }
      .ivu-menu {
        li {
          padding: 0;
          margin-right: 15px;
          border: none;
        }
      }
      .ivu-menu-horizontal {
        height: 3.5rem;
        line-height: 3.5rem;
      }
      .ivu-menu-horizontal.ivu-menu-light:after {
        display: none;
      }
    }
  }
  .main {
    position: relative;
    display: flex;
    flex-direction: row;
    margin: 0 auto;
    width: inherit;
    max-width: 960px;
    // min-height: 100vh;
    .main-left {
      width: 700px;
      margin-right: 20px;
    }
    .main-right {
      flex: 1;
    }
  }
}

@media screen and (max-width: 960px) {
  .main-box .main .main-left {
    width: 100%;
    margin: 0;
  }
  .main-right {
    display: none;
  }
}
@media screen and (max-width: 980px) {
  .main-box .category-list .category-item {
    margin: 0 15px;
  }
}
</style>